import React, { Component } from 'react'

export default class New extends Component {
  constructor () {
    super()
    console.log('--new-- constructor--')
    this.state = {
      name: '李华'
    }
  }
  static getDerivedStateFromProps (prevProps, prevState) {
    console.log('--getDerivedStateFromProps--', prevProps, prevState)
    return null
  }
  render () {
    console.log('--render--')
    return (
      <div>
        new
        <p>name is {this.state.name}</p>
        <p>count is {this.props.count}</p>
        <p>
          <button
            onClick={() => {
              this.setState({ name: '张文' })
            }}
          >
            更改
          </button>
        </p>
      </div>
    )
  }
  componentDidMount () {
    console.log('--- componentDidMount--')
  }
  shouldComponentUpdate () {
    console.log('---shouldComponentUpdate--')
    return true
  }
  getSnapshotBeforeUpdate (prevProps, prevState) {
    console.log('--getSnapshotBeforeUpdate--', prevProps, prevState)
    return { money: 200000 }
  }
  componentDidUpdate (prevProps, prevState, snapshot) {
    console.log('--componentDidUpdate--', prevProps, prevState, snapshot)
  }
  componentWillUnmount () {
    console.log('--componentWillUnmount--')
  }
}
